import { defineStore } from 'pinia'
import { ref } from 'vue'
import { menuApi } from '@/api'

export const useMenuStore = defineStore('menu', () => {
  const menuTree = ref<any[]>([])

  const fetchMenuTree = async () => {
    try {
      const { data } = await menuApi.getMenuTree()
      menuTree.value = data
    } catch (error) {
      console.error('獲取菜單樹失敗:', error)
    }
  }

  return {
    menuTree,
    fetchMenuTree,
  }
})
